/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.webservice.pa;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

/**
 *
 * @author OANHHUYNH
 */
@WebService()
public class AndroidWebservice {
    ResultSet rs;
    PreparedStatement pst;
    Connection cn = null;

    @WebMethod()
    public Customer getCustomerByCustomerName(@WebParam(name = "cust_name")String name){
        Customer customer = new Customer();
        try{
            ResultSet result = null;
            cn = ConnectionClass.getConnectionDB();
            String sql = "select * from Customer where customer_name ='"+name+"'";
            pst = cn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE);
            result = pst.executeQuery();

            if(result.next()){

            customer.setCustomer_name(result.getString("customer_name"));
            customer.setPassword(result.getString("password"));
            customer.setNames(result.getString("names"));
            customer.setDateOfBirth(result.getString("dateOfBirth"));
            customer.setAddress(result.getString("address"));
            customer.setPhone(result.getString("phone"));
            customer.setEmail(result.getString("email"));

            }
        }catch(Exception ex){

        }
        return customer;


    }
    @WebMethod()
    public ArrayList<Customer> getListCustomer(){
        ArrayList<Customer> list = new ArrayList<Customer>();
        try{
            cn = ConnectionClass.getConnectionDB();
            String sql = "select * from Customer";
            pst = cn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE);
            rs = pst.executeQuery();
            while(rs.next()){
                Customer customers = new Customer();
                customers.setCustomer_name(rs.getString("customer_name"));
                customers.setPassword(rs.getString("password"));
                customers.setNames(rs.getString("names"));
                customers.setDateOfBirth(rs.getString("dateOfBirth"));
                customers.setAddress(rs.getString("address"));
                customers.setPhone(rs.getString("phone"));
                customers.setEmail(rs.getString("email"));
                list.add(customers);
            }


        }catch(Exception ex){

        }
        return list;
    }

}
